/**
 * @author eli.hou
 * 租赁
 */
public class Rental {

    private Movie movie;
    private int daysRented;

    public Rental(Movie movie, int daysRented) {
        this.movie = movie;
        this.daysRented = daysRented;
    }

    public Movie getMovie() {
        return movie;
    }

    public void setMovie(Movie movie) {
        this.movie = movie;
    }

    public int getDaysRented() {
        return daysRented;
    }

    public void setDaysRented(int daysRented) {
        this.daysRented = daysRented;
    }

    /**
     * 该方法是由Customer类的amountFor()方法移植过来
     *
     * 代码为了适应新家，意味着要去掉参数，然后在迁移的同时改变函数名称
     *
     * switch语句，最好不要在另一个对象的属性基础上运用switch语句。如果不得不使用，也应该在对象自己的数据上使用，而不是在别人的数据上使用
     * 所以，switch语句应该迁移到Rental类中
     */
    double getCharge() {
        double result = 0;
        //determine amounts for each line
        switch (getMovie().getPriveCode()){
            case  Movie.REGULAR:
                result += 2;
                if(getDaysRented() > 2)
                    result += (getDaysRented() - 2) * 1.5;
                break;
            case Movie.NEW_RELEASE:
                result += getDaysRented() * 3;
                break;
            case Movie.CHILDRENS:
                result += 1.5;
                if (getDaysRented() > 3)
                    result += (getDaysRented() - 3) * 1.5;
                break;
        }
        return result;
    }

    int getFrequentRenterPoints() {
        if ((getMovie().getPriveCode() == Movie.NEW_RELEASE) &&
                getDaysRented() > 1 ) return 2;
        else
            return 1;
    }
}
